package com.my.screenadapter.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;

/**
 * Created by zhangyingjie on 2020/8/18
 *
 * @function
 */
public class DebugUtils {
    //已测试
    // 编译 assemble debug release 得到不同结果
    public static boolean isApkInDebug(Context context) {
        try {
            ApplicationInfo info =  context.getApplicationInfo();
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * todo 待测试
     *检测其他应用是否处于debug模式。
     */
    public static boolean isApkDebugable(Context context,String packageName) {
        try {
            PackageInfo pkginfo = context.getPackageManager().getPackageInfo(
                    packageName, 1);
            if (pkginfo != null ) {
                ApplicationInfo info= pkginfo.applicationInfo;
                return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
            }
        } catch (Exception e) {

        }
        return false;
    }
}
